import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'

Vue.use(VueRouter)

// 解决重复路由报错

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
// 解决重复路由报错

const routes = [
  { path: '/', redirect: '/home'}, 
  {path: '/home',component: () => import('../views/Home.vue')},
  {path: '/project',component: () => import('../views/Project.vue')},
  {path: '/room',name:'room',component: () => import('../views/Room.vue')},
  {path: '/roomDetail',component: () => import('../views/roomDetail.vue')},
  {path: '/detail',component: () => import('../views/detail.vue')},
  {path: '/projectDetail',component: () => import('../views/projectDetail.vue')},
  {path: '/projectalbum',name:"projectalbum",component: () => import('../views/projectalbum.vue')},
  {path: '/user',component: () => import('../views/user.vue')},
  {path: '/understand',component: () => import('../views/understand.vue')},
  {path: '/work',component: () => import('../views/work.vue')},
  {path: '/understandcopy',component: () => import('../views/understandcopy.vue')},
  {path: '/workcopy',component: () => import('../views/workcopy.vue')},
  {path: '/search',component: () => import('../views/search.vue')},
  {path: '/friends',component: () => import('../views/friends.vue')},
  // 用户信息
  {path: '/withdrawform',component: () => import('../views/withdrawform.vue')},
  {path: '/sure',component: () => import('../views/sure.vue')},
  {path: '/follow',component: () => import('../views/follow.vue')},
  {path: '/userInfo',component: () => import('../views/userInfo.vue')},
  {path: '/withdrawlist',component: () => import('../views/withdrawlist.vue')},
  // 登录
  {path: '/login',component: () => import('../views/login.vue')},
  // 注册
  {path: '/resigion',component: () => import('../views/resigion.vue')},
  // 上下级
  {path: '/lower',component: () => import('../views/lower.vue')},
  {path: '/highter',component: () => import('../views/highter.vue')}
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 路由守卫
// 路由守卫核心代码
// router.beforeEach((to,from,next) => {
  
//   var userInfo = window.sessionStorage.getItem("token")
  
//   //然后判断要去往的页面，如果是去往login和register页面的，就直接放行
//   //如果不是去往login和register页面，则判断有没有token，如果有token就放行，否则就跳转login页面
//   if (to.path == '/userInfo' || to.path == '/register') {
//     next
//   }else {
//     userInfo=="" ? next('/home') : next()
//   }
// })


export default router
